Skip to content

fix(search): use all memory_types in search API instead of only first one#104

Open
r266-tech wants to merge 1 commit intoEverMind-AI:mainfrom
r266-tech:fix/search-all-memory-types
Open

fix(search): use all memory_types in search API instead of only first one#104
r266-tech wants to merge 1 commit intoEverMind-AI:mainfrom
r266-tech:fix/search-all-memory-types

Conversation

@r266-tech
Copy link

Summary

Fixes #78 — Search API only uses memory_types[0], silently ignoring all other types.

Problem

All retrieval methods (get_keyword_search_results, get_vector_search_results, _search_hybrid, _search_rrf, retrieve_mem_agentic) hardcoded memory_types[0]:

mem_type = memory_types[0]  # Only first type ever searched!

Impact:

  • Case 1 (silent data loss): memory_types=episodic_memory,foresight → only episodic_memory is searched. foresight silently ignored.
  • Case 2 (error): memory_types=profile,episodic_memoryprofile (not in ES/Milvus) taken as [0] → ERROR. All valid types never searched.

Fix

get_keyword_search_results

  • Iterates over all memory_types
  • For each type: checks ES_REPO_MAP → search if supported, skip with logger.info if not
  • Merges results from all types into a single list

get_vector_search_results

  • Computes embedding once (same query vector for all types)
  • Iterates over all memory_types
  • For each type: checks MILVUS_REPO_MAP → search if supported, skip with logger.info if not
  • Handles foresight-specific time range params per-type
  • Merges all results

Infrastructure

  • Added module-level MILVUS_REPO_MAP dict (mirrors existing ES_REPO_MAP)
  • Added _memory_types_label() helper for metrics/logging (returns comma-joined types string)
  • Updated _to_response metadata to use joined types instead of just first type
  • All metrics recording across all methods updated

What is NOT changed

  • Function signatures unchanged
  • Response format (RetrieveMemResponse) unchanged
  • Dedup/rerank logic unchanged (operates on merged flat list)
  • profile type remains intentionally unsearchable (MongoDB-only, fetch API)

Tests

Added tests/test_memory_manager_search.py with 15 unit tests:

Test Class Coverage
TestMemoryTypesLabel Helper function: single/multiple/empty/three types
TestGetKeywordSearchResults Multi-type merge, PROFILE skip, single type, empty list, empty repo results
TestGetVectorSearchResults Multi-type merge, PROFILE skip, single type, empty list, embedding-called-once, foresight special params

… one

Previously, all retrieval methods (keyword, vector, hybrid, RRF, agentic)
only used memory_types[0], silently ignoring all other types in the list.
If the first type was unsupported (e.g. profile), the entire search errored out.

Changes:
- get_keyword_search_results: iterate over ALL memory_types, search each
  supported type via ES_REPO_MAP, skip unsupported types with info log,
  merge results
- get_vector_search_results: compute embedding ONCE, iterate over ALL
  memory_types, search each supported Milvus repo, skip unsupported types,
  merge results (foresight special params handled per-type)
- Add module-level MILVUS_REPO_MAP dict for cleaner repo lookup
- Add _memory_types_label() helper for metrics/logging across all methods
- _to_response uses joined memory types string for metadata

Also adds comprehensive unit tests covering multi-type search, unsupported
type skipping, single type backward compatibility, and embedding-once
verification.

Closes EverMind-AI#78
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Search API only uses memory_types[0], silently ignoring all other types

1 participant